1 00:00:01,090 --> 00:00:01,660 All right. 2 00:00:01,660 --> 00:00:06,100 So in this next section of the course we're going to take a dive into type annotation. 3 00:00:06,100 --> 00:00:10,000 If you've been in my beginner's course, you'll know that type annotation is a way for us to specify 4 00:00:10,000 --> 00:00:16,000 the type of a variable, a parameter or return value of a function, and it helps the Lua compiler perform 5 00:00:16,000 --> 00:00:20,650 type checking when the script gets compiled, it can help us understand our code easier as well as for 6 00:00:20,650 --> 00:00:25,030 other developers, and it can also highlight problems to us when functions we create are not being passed. 7 00:00:25,030 --> 00:00:26,260 The correct arguments. 8 00:00:26,260 --> 00:00:31,060 Type annotations also allow us to use auto completion for when accessing properties of a particular 9 00:00:31,060 --> 00:00:34,870 type, when the compiler doesn't know a type of a variable, but we do. 10 00:00:35,370 --> 00:00:40,380 We can declare the type of a variable in Lua you using a colon, and then write in the name of the type. 11 00:00:40,380 --> 00:00:45,360 We can do this for all of the primitive types in Lua such as booleans, numbers, nil strings, and 12 00:00:45,360 --> 00:00:46,080 so on. 13 00:00:46,200 --> 00:00:49,320 So if I were to create a variable, I can call it anything I want. 14 00:00:49,320 --> 00:00:53,730 I'll just call it some var and I can use a colon right after the name. 15 00:00:53,730 --> 00:00:58,800 And from here I can define the type that this variable is going to be such as number. 16 00:00:58,800 --> 00:01:03,480 And in here it'll show us all the types that we can set for this variable with this new text. 17 00:01:03,480 --> 00:01:05,100 So we're going to set it to number. 18 00:01:05,640 --> 00:01:10,140 And now when I go to type out this variable you'll see here right on the right, it tells us that the 19 00:01:10,140 --> 00:01:13,170 type of this variable is type of number. 20 00:01:13,380 --> 00:01:17,250 So I can set this to anything I'd like such as 123. 21 00:01:17,250 --> 00:01:20,790 And we have no problem here inside of studio. 22 00:01:20,910 --> 00:01:23,700 Now this is where some modes come into play. 23 00:01:23,700 --> 00:01:27,450 So the compiler does something called type inferencing. 24 00:01:27,450 --> 00:01:34,980 Or it can infer the type of a variable or a parameter, or a return of a function by itself based on 25 00:01:34,980 --> 00:01:36,450 what values we assign to it. 26 00:01:36,450 --> 00:01:41,850 So by default, Lua already knows that this type of the variable is going to be a number because we're 27 00:01:41,850 --> 00:01:42,840 assigning it a number. 28 00:01:42,840 --> 00:01:47,910 So if I got rid of this type declaration here and I want to type in some var c, it already says to 29 00:01:47,910 --> 00:01:50,430 us that it's a number because we assigned it a number. 30 00:01:50,430 --> 00:01:56,820 But if we didn't initialize this variable, if we go and type it out again, you'll see it says A which 31 00:01:56,820 --> 00:01:57,960 stands for any. 32 00:01:57,960 --> 00:02:02,580 So that means the compiler is saying hey, this variable hasn't been instantiated. 33 00:02:02,580 --> 00:02:03,990 We don't know what's going to be stored in it. 34 00:02:03,990 --> 00:02:10,140 So it can store anything, but we can override it and say maybe this variable is going to store maybe 35 00:02:10,140 --> 00:02:10,950 a player. 36 00:02:13,320 --> 00:02:18,720 And now when we go and type out some var, it will tell us, hey, this is going to be a player data 37 00:02:18,720 --> 00:02:20,190 type for this variable. 38 00:02:20,640 --> 00:02:24,480 Now this inferencing can change based on the modes that we select for the script. 39 00:02:24,480 --> 00:02:25,770 So there's three modes. 40 00:02:25,770 --> 00:02:27,510 There's one called no check. 41 00:02:27,510 --> 00:02:30,510 There's one called non strict and there's one called strict. 42 00:02:30,510 --> 00:02:35,160 Now no check means that the inference mode is not going to be enabled at all. 43 00:02:35,160 --> 00:02:38,910 The inference engine in Roblox studio won't be enabled whatsoever. 44 00:02:38,910 --> 00:02:42,780 So it's not going to go ahead and infer any of the types for the variables. 45 00:02:42,780 --> 00:02:47,520 Usually I can't really think of a use case for no check, but we're going to go ahead and move on to 46 00:02:47,520 --> 00:02:48,240 non strict. 47 00:02:48,240 --> 00:02:51,810 Now this is the type inferencing mode that is enabled by default. 48 00:02:51,900 --> 00:02:57,600 And the way you enable a type inference mode is that at the top of your script before you write down 49 00:02:57,600 --> 00:03:02,760 any code, you can create a comment and use an exclamation mark and type the name of the mode you want 50 00:03:02,760 --> 00:03:08,520 for the type annotation, such as no check or you can do non strict, which would make sense because 51 00:03:08,520 --> 00:03:12,270 it's enabled by default and then the other one would be strict. 52 00:03:12,630 --> 00:03:17,610 So this is telling the compiler hey this is what kind of inferencing mode we want you to have for the 53 00:03:17,610 --> 00:03:19,050 variables in our script. 54 00:03:19,320 --> 00:03:23,340 So we're going to keep it on strict that way we can see some examples later on. 55 00:03:23,340 --> 00:03:27,540 And strict is basically the same thing as non strict. 56 00:03:27,540 --> 00:03:35,190 And what non strict does is that it will infer basically any variable parameter or return from a function 57 00:03:35,190 --> 00:03:36,960 that it can't figure out to any. 58 00:03:36,960 --> 00:03:42,870 So for example here, this variable I didn't instantiate, it's automatically set to any right because 59 00:03:42,870 --> 00:03:43,410 it doesn't know. 60 00:03:43,410 --> 00:03:45,390 It's inferring that it could be anything at all. 61 00:03:45,390 --> 00:03:47,760 That's what the non strict mode does. 62 00:03:47,880 --> 00:03:55,170 Now what the strict mode does is that this inference mode um, it will throw out an error if the number 63 00:03:55,170 --> 00:03:58,470 of parameters that you pass to a function is inappropriate. 64 00:03:58,470 --> 00:04:04,080 Basically, if you pass more parameters to a function that's not specified or you don't pass enough 65 00:04:04,080 --> 00:04:07,320 parameters to a function, then it's going to throw out an error. 66 00:04:07,320 --> 00:04:11,190 It's going to highlight the script and say, hey, you don't have enough arguments being supplied to 67 00:04:11,190 --> 00:04:11,970 a function. 68 00:04:12,060 --> 00:04:16,800 So let's go ahead and create some variable examples for each one of the primitive types. 69 00:04:16,800 --> 00:04:19,530 So for one I could call it some bool. 70 00:04:20,050 --> 00:04:24,100 And we can set it to be a boolean just like this. 71 00:04:24,340 --> 00:04:27,250 And now studio sees it as a boolean. 72 00:04:27,460 --> 00:04:29,320 We can do the same thing for a number. 73 00:04:29,320 --> 00:04:32,650 So we could do some number and set the type to be number. 74 00:04:32,650 --> 00:04:34,090 So again some number. 75 00:04:34,090 --> 00:04:36,370 It's telling us the type is of a number. 76 00:04:36,610 --> 00:04:38,200 We can do nil. 77 00:04:38,200 --> 00:04:41,560 So we could do some nil and set it to nil. 78 00:04:41,740 --> 00:04:46,420 And when you go and check here it tells us that the type is going to be nil. 79 00:04:46,810 --> 00:04:48,610 You can do the same thing for strings. 80 00:04:48,610 --> 00:04:49,930 So some string. 81 00:04:50,520 --> 00:04:52,740 Declare that this type will be of string. 82 00:04:52,740 --> 00:04:56,880 And you go here, you look for some string and there we go tells us it's a string. 83 00:04:57,120 --> 00:05:00,210 And then for functions it's going to be a little bit different. 84 00:05:00,210 --> 00:05:02,700 So for function you can't do function. 85 00:05:02,700 --> 00:05:03,750 It doesn't work like that. 86 00:05:03,750 --> 00:05:06,870 What you actually have to do is you have to put two colons. 87 00:05:06,870 --> 00:05:12,480 And then after these two colons you do a dash and an arrow to tell you what this function is going to 88 00:05:12,480 --> 00:05:12,900 return. 89 00:05:12,900 --> 00:05:14,400 And I'm just going to set it to nil. 90 00:05:14,400 --> 00:05:19,020 So what this is declaring here is it's telling us that this variable is going to store a function that 91 00:05:19,020 --> 00:05:21,960 takes no parameters and it returns nil. 92 00:05:22,630 --> 00:05:28,870 So if I go to some function, it tells us that some function that takes no parameters and returns nil. 93 00:05:29,530 --> 00:05:30,940 Now I could do anything here. 94 00:05:30,940 --> 00:05:35,080 I could say, hey, maybe this function returns a player and we go and check some function. 95 00:05:35,080 --> 00:05:37,330 Now it's telling us it returns a player. 96 00:05:37,330 --> 00:05:39,640 And then I can also declare parameters in here. 97 00:05:39,640 --> 00:05:41,590 So let's say some param. 98 00:05:41,590 --> 00:05:44,470 And this parameter needs to be I don't know a number. 99 00:05:44,470 --> 00:05:49,900 When we go and type out some function again it tells us that this function takes a parameter which has 100 00:05:49,900 --> 00:05:52,240 to be a number and it returns to us a player. 101 00:05:52,240 --> 00:05:57,190 So this is how you declare the type for a variable that is going to be a function. 102 00:05:57,190 --> 00:05:59,290 And then for a table, it's pretty simple. 103 00:05:59,290 --> 00:06:04,090 We can do some table, and all we need to do is put two curly brackets. 104 00:06:04,090 --> 00:06:07,780 So this is denoting that some table is a table. 105 00:06:07,780 --> 00:06:09,670 And currently there is nothing in it. 106 00:06:09,670 --> 00:06:15,100 But if we want to define some, you know, thing that this variable can only contain, like it has to 107 00:06:15,100 --> 00:06:19,240 have some set of properties in the table or key value pairs. 108 00:06:19,240 --> 00:06:26,500 We could do something like uh, some key and this key has to contain maybe a boolean. 109 00:06:26,500 --> 00:06:27,070 Right. 110 00:06:27,070 --> 00:06:30,010 So if we go and look at some table again. 111 00:06:30,750 --> 00:06:34,740 It's telling us that there is some key in here, and it has to be a buoyant. 112 00:06:35,620 --> 00:06:42,130 Now, if I go ahead and try to assign a table to this variable, this table has to contain this some 113 00:06:42,130 --> 00:06:44,050 key and it has to store a boolean. 114 00:06:44,050 --> 00:06:50,260 Otherwise you'll see here table type some table not compatible with this type because it's missing the 115 00:06:50,260 --> 00:06:51,250 field some key. 116 00:06:51,250 --> 00:06:56,170 So I actually have to put a field in here called some key and assign it a boolean value like false. 117 00:06:56,170 --> 00:06:58,510 And you see we don't get that red underline anymore. 118 00:06:58,510 --> 00:07:03,490 But if I set it to something like one, two, three we're going to get an error because we cannot convert 119 00:07:03,490 --> 00:07:06,310 a number into a boolean which is required right here. 120 00:07:06,310 --> 00:07:06,670 Right. 121 00:07:06,670 --> 00:07:12,520 We're telling the compiler or telling studio that this key right here has to be a boolean. 122 00:07:12,520 --> 00:07:16,780 If we assign it to anything other than a boolean, it's going to give us this red underline and tell 123 00:07:16,780 --> 00:07:18,700 us that there is a problem going on. 124 00:07:19,450 --> 00:07:20,440 So this right here. 125 00:07:20,440 --> 00:07:21,220 This is not okay. 126 00:07:21,220 --> 00:07:22,330 You don't want to do this. 127 00:07:23,100 --> 00:07:26,550 Instead, we want to make sure we set some key to a boolean. 128 00:07:27,280 --> 00:07:28,510 And we're all good to go. 129 00:07:28,510 --> 00:07:28,870 No. 130 00:07:28,870 --> 00:07:29,860 Red underline. 131 00:07:29,890 --> 00:07:32,590 Now let's go ahead and take a look at some Roblox data types. 132 00:07:32,590 --> 00:07:37,390 So if I create a new part using the instance dot new function part. 133 00:07:38,610 --> 00:07:44,100 What you're going to see here is that Roblox studio automatically knows that this variable is going 134 00:07:44,100 --> 00:07:50,250 to contain the type part, because the instance dot new function, when given this part string, returns 135 00:07:50,250 --> 00:07:56,520 a part back to be stored in this variable, so it automatically knows that it is of the type part. 136 00:07:56,520 --> 00:07:59,280 So there's no need to go ahead and put part here. 137 00:07:59,280 --> 00:08:00,330 It already knows that. 138 00:08:01,150 --> 00:08:06,640 So let's do like a small little example with a function I'm going to create a function. 139 00:08:06,640 --> 00:08:09,370 I'll call it ad numb's. 140 00:08:09,370 --> 00:08:11,590 So it's going to add two numbers together. 141 00:08:11,590 --> 00:08:16,060 And we're going to take two parameters one number and a second number. 142 00:08:16,060 --> 00:08:19,030 So we can call one number a and the other number b. 143 00:08:20,400 --> 00:08:21,900 And I create my function right here. 144 00:08:21,900 --> 00:08:27,210 Now, when I go to call this function, it just tells us that A is a, B is B. 145 00:08:27,210 --> 00:08:31,140 It's not telling us exactly what type these variables have to be. 146 00:08:31,140 --> 00:08:33,750 It's basically telling us we can pass whatever we want. 147 00:08:33,750 --> 00:08:40,860 But when we want to make sure to pass only a specific type to this function, then we can go ahead and 148 00:08:40,860 --> 00:08:43,770 go to where these parameters are declared and put a colon. 149 00:08:43,770 --> 00:08:46,830 And we have to say, okay, a is going to be a number. 150 00:08:47,560 --> 00:08:50,080 And B also has to be a number. 151 00:08:50,080 --> 00:08:56,770 And when we go to call the Adnams function, it tells us a has to be a number, B has to be a number. 152 00:08:57,010 --> 00:09:03,910 And if we try to pass anything else like a boolean, like false or a string, uh, hello again. 153 00:09:03,910 --> 00:09:10,330 It's going to underline and tell us that we can't convert type of string to a number, or we can't convert 154 00:09:10,330 --> 00:09:12,370 type of boolean to number. 155 00:09:12,370 --> 00:09:16,150 It's telling us, hey, you can only pass numbers to this function. 156 00:09:16,390 --> 00:09:19,990 Now what if I also wanted to define what this function returns? 157 00:09:19,990 --> 00:09:21,880 Well that's also really simple. 158 00:09:21,880 --> 00:09:25,330 We can put a colon at the end of this parentheses. 159 00:09:25,330 --> 00:09:29,110 And then we can tell exactly what this function is going to return. 160 00:09:29,110 --> 00:09:30,490 So what is it going to return. 161 00:09:30,490 --> 00:09:33,460 Well it's going to return a sum of these two numbers. 162 00:09:33,460 --> 00:09:35,560 So we'll just return a number. 163 00:09:35,560 --> 00:09:38,140 And then when we go and call this function again. 164 00:09:39,100 --> 00:09:45,010 It's telling us it takes a number for a, takes a number for B, and it returns to us a number. 165 00:09:45,010 --> 00:09:50,530 So this is how we can declare what types are going to be returned or given to a function. 166 00:09:50,530 --> 00:09:55,840 And then from this point we can just do return a plus B. 167 00:09:56,260 --> 00:10:00,730 And because we're returning two numbers, in fact, we actually don't even need to declare what this 168 00:10:00,730 --> 00:10:04,990 function returns, because if we store what this function returns. 169 00:10:04,990 --> 00:10:12,040 So we'll create a variable, call it some num and equal to add numb's we'll pass a number here and a 170 00:10:12,040 --> 00:10:12,970 number here. 171 00:10:13,270 --> 00:10:15,010 We'll go to type out some num. 172 00:10:15,010 --> 00:10:16,960 Of course it's going to tell us it's a number. 173 00:10:16,960 --> 00:10:24,130 But even if we remove this here and we type out some num some num, it still tells us it's a number 174 00:10:24,130 --> 00:10:26,740 because we're passing in a number to this function. 175 00:10:26,740 --> 00:10:29,830 And all this function is doing is adding those two numbers and returning it. 176 00:10:29,830 --> 00:10:35,410 So the compiler or studio automatically sees, hey, this is returning a number, no big deal. 177 00:10:35,410 --> 00:10:40,000 However, there may be cases where we're going to have a lot more complex number, and studio is not 178 00:10:40,000 --> 00:10:44,380 going to be able to figure out what type is being returned from a function, which is why it's sometimes 179 00:10:44,380 --> 00:10:46,540 good to declare what a function returns. 180 00:10:46,540 --> 00:10:51,100 Again, it makes using your functions a lot easier because you know what it returns. 181 00:10:51,100 --> 00:10:56,530 You know what it takes, and then it also helps us out when we go to type out the name of this variable 182 00:10:56,530 --> 00:11:01,480 and it gives us oops, we get an error type because we, uh, we didn't finish out. 183 00:11:02,070 --> 00:11:02,820 This function. 184 00:11:02,820 --> 00:11:04,110 So again we'll do one two. 185 00:11:04,590 --> 00:11:06,900 When we type out the name it tells us the number. 186 00:11:06,900 --> 00:11:11,970 And we can access all the properties for this variable in case it was like a Roblox data type. 187 00:11:11,970 --> 00:11:16,470 Now another topic I want to take a look at is optional parameters for a function. 188 00:11:16,470 --> 00:11:21,480 So let's say I don't really actually need to supply B to this function. 189 00:11:21,480 --> 00:11:25,860 I can only take a, and if B doesn't exist, I can set it to a default value. 190 00:11:25,860 --> 00:11:33,660 So what I could do is I could set B equal to itself, or if B was never passed to the function, I could 191 00:11:33,660 --> 00:11:35,070 set it to a number like one. 192 00:11:35,070 --> 00:11:36,930 And this is going to be our default. 193 00:11:36,930 --> 00:11:37,590 Right. 194 00:11:37,710 --> 00:11:43,680 And then to declare B as optional, I can just put a question mark after the number. 195 00:11:43,680 --> 00:11:49,380 And now when I go and supply just the number one to this function, we're not going to have an error 196 00:11:49,380 --> 00:11:49,980 here. 197 00:11:49,980 --> 00:11:55,260 However, if I got rid of this question mark, we're going to get this underline and say we did not. 198 00:11:55,260 --> 00:11:57,720 We didn't pass enough arguments to this function. 199 00:11:57,720 --> 00:11:58,800 We need to pass another one. 200 00:11:58,800 --> 00:12:03,330 But if I want B to be optional I just added a question mark and the problem is solved. 201 00:12:03,360 --> 00:12:07,350 Now you're going to see that B gets underlined and it's telling us type number. 202 00:12:07,350 --> 00:12:09,840 Question mark cannot be converted into number. 203 00:12:09,840 --> 00:12:14,700 And the issue here is that studio just isn't smart enough to figure out that we've actually set B to 204 00:12:14,700 --> 00:12:16,200 a default, which is a number. 205 00:12:16,590 --> 00:12:21,390 So if you don't like this red underline here, what you could do is you could create an if statement 206 00:12:21,390 --> 00:12:23,130 that does something like this. 207 00:12:23,130 --> 00:12:30,750 So if B then you could do return a and B and you see that red underline disappears because studio might 208 00:12:30,750 --> 00:12:35,010 think that B could possibly be nil, which is why it gives that underline there. 209 00:12:35,010 --> 00:12:41,070 But when we do it this way then you see we'll have another underline because we're not returning a number 210 00:12:41,070 --> 00:12:45,480 here, because if B doesn't exist then the function returns nothing. 211 00:12:45,480 --> 00:12:47,760 But that doesn't happen because we set a default here. 212 00:12:47,760 --> 00:12:52,260 But again, the compiler or studio isn't smart enough to figure that out. 213 00:12:52,260 --> 00:12:54,510 So you're just getting these weird underlines. 214 00:12:54,990 --> 00:12:57,480 So I wouldn't really worry about it too much. 215 00:12:57,480 --> 00:13:00,750 Just return a plus B, you'll just get this little red underline. 216 00:13:00,750 --> 00:13:01,800 Don't worry about it. 217 00:13:02,160 --> 00:13:08,220 But let's move on and let's create another function I'm going to call this function uh I don't know 218 00:13:08,220 --> 00:13:10,800 get random instance. 219 00:13:10,800 --> 00:13:15,360 And we could just say, oh, you know, this, uh, we need to pass a player to this function. 220 00:13:15,360 --> 00:13:15,630 Right. 221 00:13:15,630 --> 00:13:17,790 So we'll have a variable just called player. 222 00:13:17,790 --> 00:13:20,010 And this variable has to be a player. 223 00:13:20,520 --> 00:13:25,890 And we could declare that this function returns, I don't know, maybe a part. 224 00:13:25,890 --> 00:13:26,220 Right. 225 00:13:26,220 --> 00:13:29,220 So we get a part, set it to part. 226 00:13:29,220 --> 00:13:32,430 And this function, you know, does whatever, blah blah blah. 227 00:13:32,430 --> 00:13:35,820 And it can return to us, um, some part. 228 00:13:35,820 --> 00:13:38,250 So some part will create a variable in here. 229 00:13:39,840 --> 00:13:43,800 And perhaps it equals to like instance that new part or something like that. 230 00:13:45,530 --> 00:13:48,530 So whenever we get something returned from this function. 231 00:13:48,530 --> 00:13:56,540 So some part equal to get random instance, we could pass um instance dot new player just for this example. 232 00:13:57,530 --> 00:14:01,490 Some part is going to be a part. 233 00:14:01,490 --> 00:14:06,290 So some part there we go tells us it is of type part. 234 00:14:06,290 --> 00:14:10,100 If we got rid of this I'm pretty sure it will say type part. 235 00:14:10,100 --> 00:14:10,640 There we go. 236 00:14:10,640 --> 00:14:14,090 Because it knows that the instance dot new function returns a part. 237 00:14:14,090 --> 00:14:19,490 It sets that type to this variable, and then that variable simply gets returned and stored in here. 238 00:14:19,490 --> 00:14:22,670 So that's why it still says it is of the type part. 239 00:14:22,670 --> 00:14:28,820 It's kind of hard to give an example of when you'll have a complex function that the compiler won't 240 00:14:28,820 --> 00:14:34,970 be able to interpret what type it returns, but we're going to be using type annotations and type inferencing 241 00:14:34,970 --> 00:14:36,710 later in the course on our projects. 242 00:14:36,710 --> 00:14:42,500 So it's just good practice to declare what a function returns, which is not a player, it's a part. 243 00:14:43,130 --> 00:14:46,100 And I can show you another example of something that's not okay. 244 00:14:46,130 --> 00:14:52,400 Let's say I had another number like some number two, and I say it's a boolean, but I set it equal 245 00:14:52,400 --> 00:14:55,550 to the Adnams function and pass like one and three. 246 00:14:55,580 --> 00:14:57,980 Again we're going to get a red underline. 247 00:14:57,980 --> 00:15:02,750 It says type number could not be converted into boolean because this function is returning a variable 248 00:15:02,750 --> 00:15:03,980 of type number. 249 00:15:03,980 --> 00:15:07,430 And you can't store in a variable of a type boolean. 250 00:15:07,430 --> 00:15:07,940 Right. 251 00:15:07,940 --> 00:15:11,420 So this this is not okay. 252 00:15:11,420 --> 00:15:12,590 Don't do this. 253 00:15:12,860 --> 00:15:14,120 This is okay. 254 00:15:14,120 --> 00:15:15,380 This is not okay. 255 00:15:15,770 --> 00:15:20,930 So this would fall under inferring the returns of functions. 256 00:15:20,930 --> 00:15:21,890 So again. 257 00:15:23,350 --> 00:15:26,920 Studio knows that some num is a number. 258 00:15:27,910 --> 00:15:34,360 Even if we do not declare that it returns a number, it's simply inferring that based on what gets supplied 259 00:15:34,360 --> 00:15:37,150 to the function and what gets returned from the function. 260 00:15:37,150 --> 00:15:42,220 So this is the compiler inferring to us what the type of this variable is going to be. 261 00:15:42,250 --> 00:15:47,080 One last thing I want to touch on real quick is of course auto completion. 262 00:15:47,080 --> 00:15:51,550 So if we had a function that does something, does something. 263 00:15:53,220 --> 00:15:55,350 And it requires a parameter. 264 00:15:55,350 --> 00:15:57,750 We'll just call it some param. 265 00:15:58,020 --> 00:16:03,810 And we know that we need to supply like a, perhaps a part. 266 00:16:03,810 --> 00:16:06,150 We have to supply a part to this function. 267 00:16:06,150 --> 00:16:09,510 But of course the compiler doesn't know that some param is going to be a part. 268 00:16:09,510 --> 00:16:12,780 So when we index it it doesn't really know what we're indexing. 269 00:16:12,780 --> 00:16:13,350 Right. 270 00:16:13,350 --> 00:16:21,240 But if we go in here and we set it to be of type part and we go and index it, then we get the autocompletion 271 00:16:21,240 --> 00:16:28,410 and we get all of the properties, the events and all this good stuff that is a part of a part. 272 00:16:28,410 --> 00:16:35,160 So it makes it really easy for us to use Autocompletion or access any types of events or functions because 273 00:16:35,160 --> 00:16:36,300 they can get auto filled for us. 274 00:16:36,300 --> 00:16:42,570 So when we type P set to parent, we can tab to autocomplete and it helps to make us more efficient. 275 00:16:42,570 --> 00:16:48,600 So again the purpose of type inferencing is to make your scripts easier to understand for you and other 276 00:16:48,600 --> 00:16:49,500 developers. 277 00:16:49,500 --> 00:16:54,660 It helps you use Autocompletion as you've seen here, and it also gives you a great understanding of 278 00:16:54,660 --> 00:16:58,050 what exactly the types of variables are that you're working with. 279 00:16:58,050 --> 00:17:03,450 So when you have a bunch of variables in a script and you have to use them a bunch in your code, it's 280 00:17:03,450 --> 00:17:04,500 going to help a lot. 281 00:17:04,500 --> 00:17:09,360 When you can type out that variable name, it tells you exactly the type of that variable, and you 282 00:17:09,360 --> 00:17:14,340 can go in and access all the properties you need for that specific variable based on its type. 283 00:17:14,760 --> 00:17:17,190 So this was a lot of information to digest. 284 00:17:17,190 --> 00:17:20,730 But we're going to continue working with types in this section. 285 00:17:20,730 --> 00:17:22,650 And I'll see you in the next lecture.